popover: Respect alignment for positioning
authorMatthias Clasen <mclasen@redhat.com>
Sat, 8 Jun 2019 03:14:02 +0000 (03:14 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 9 Jun 2019 17:38:54 +0000 (17:38 +0000)
We lost the code that takes the halign of
the popover into account when positioning it.
Bring it back, since we want to use it for
popover menus.

gtk/gtkpopover.c

index 25fdbf23b065f7718e276d2c6461bb5c93d709ae..55db0e23cfc8382903d51dbe0706a9c5be68df6b 100644 (file)
@@ -259,14 +259,50 @@ move_to_rect (GtkPopover *popover)
       break;
 
     case GTK_POS_TOP:
-      parent_anchor = GDK_GRAVITY_NORTH;
-      surface_anchor = GDK_GRAVITY_SOUTH;
+      switch (gtk_widget_get_halign (GTK_WIDGET (popover)))
+        {
+        case GTK_ALIGN_START:
+          parent_anchor = GDK_GRAVITY_NORTH_WEST;
+          surface_anchor = GDK_GRAVITY_SOUTH_WEST;
+          break;
+
+        case GTK_ALIGN_END:
+          parent_anchor = GDK_GRAVITY_NORTH_EAST;
+          surface_anchor = GDK_GRAVITY_SOUTH_EAST;
+          break;
+
+        case GTK_ALIGN_FILL:
+        case GTK_ALIGN_CENTER:
+        case GTK_ALIGN_BASELINE:
+        default:
+          parent_anchor = GDK_GRAVITY_NORTH;
+          surface_anchor = GDK_GRAVITY_SOUTH;
+          break;
+        }
       anchor_hints = GDK_ANCHOR_FLIP_Y | GDK_ANCHOR_SLIDE_X;
       break;
 
     case GTK_POS_BOTTOM:
-      parent_anchor = GDK_GRAVITY_SOUTH;
-      surface_anchor = GDK_GRAVITY_NORTH;
+      switch (gtk_widget_get_halign (GTK_WIDGET (popover)))
+        {
+        case GTK_ALIGN_START:
+          parent_anchor = GDK_GRAVITY_SOUTH_WEST;
+          surface_anchor = GDK_GRAVITY_NORTH_WEST;
+          break;
+
+        case GTK_ALIGN_END:
+          parent_anchor = GDK_GRAVITY_SOUTH_EAST;
+          surface_anchor = GDK_GRAVITY_NORTH_EAST;
+          break;
+
+        case GTK_ALIGN_FILL:
+        case GTK_ALIGN_CENTER:
+        case GTK_ALIGN_BASELINE:
+        default:
+          parent_anchor = GDK_GRAVITY_SOUTH;
+          surface_anchor = GDK_GRAVITY_NORTH;
+          break;
+        }
       anchor_hints = GDK_ANCHOR_FLIP_Y | GDK_ANCHOR_SLIDE_X;
       break;